SceneEditor.prototype.showOrHideModel=function(layerId,state,type){
	var _this=this;
	if('Models'==type){
		layer.load(2);
	    _this.ajaxFunc(_this.ctx+"/scene/model/getList",{
	    	layerId:layerId
	    }, "json", function(res){
	    	layer.closeAll('loading');
			 if (undefined!=res && 200==res.code) {
				 var list=res.data;
				 if(state==true){
					 _this.globe.addModels(list);
				 }else{
					 _this.globe.removeModels(list);
				 }
			 }
			 else{
			 }
	    });
	}else if('Model'==type){
		layer.load(2);
	    _this.ajaxFunc(_this.ctx+"/scene/model/getById",{
	    	id:layerId
	    }, "json", function(res){
	    	layer.closeAll('loading');
			 if (undefined!=res && 200==res.code) {
				 var model=res.data; 
				 if(model){
					 if(state==true){
						 _this.globe.addModel(model);
						 _this.globe.flyToModelById(model.id);
					 }else{
						 _this.globe.removeModel(model);
					 }
				 }
			 }
			 else{
			 }
	    });
	}else{
		layer.alert('未识别图层标识【"'+type+'"】！！', {icon: 1,skin: 'layer-ext-moon' })
	}
} 

/**
 * 在线底图
 */
SceneEditor.prototype.addOnLineModel=function(node){
	 var _this=this;
	 layer.load(2);
	 _this._Ajax('get',_this.ctx+"/scene/model/select",{sceneId:_this.sceneId,layerId:node.id},'html',function(e){
		layer.closeAll('loading');
	    layer.open({
	    	id:'addOnLineModel',
	        title:'模型资源库',
	        type: 1,
	        area: '330px',
	        content:e,
	        shade:0,
	        offset: ['0px', '224px'],
	        fixed:true,
	        move:false,
	        skin:'layui-layer layui-layer-adminRight layui-layer-city',
		    content: e,
		    success: function (layero, dIndex) {
	            $(layero).children('.layui-layer-content').css('overflow', 'hidden');
	            //人工模型
	            var bizModelForGLTFTb = table.render({
	                elem: '#tableBizModelForGLTFEditor',
	                url: _this.ctx+'/scene/model/listData', 
	                toolbar: false,
	                cellMinWidth: 100,
	                skin:'nob',// 无边框风格
	                page: {
	                    layout: ['prev', 'page', 'next','count'] //自定义分页布局
	                    //,curr: 5 //设定初始在第 5 页
	                    ,groups:5 //只显示 1 个连续页码
	                    ,first: false //不显示首页
	                    ,last: false //不显示尾页
	                },
	                where:{
	                	type:'GLTF',
	                },
	                cols: [[
	                    {field: 'name', sort: false, title: '名称', align: 'left'},
	                ]],
	                done: function (res, curr, count) {
	                }
	            });
	            
	            //实景模型
	            var bizModel3dtilesForTb = table.render({
	                elem: '#tableBizModelFor3DTILESEditor',
	                url: _this.ctx+'/scene/model/listData', 
	                toolbar: false,
	                cellMinWidth: 100,
	                skin:'nob',// 无边框风格
	                page: {
	                    layout: ['prev', 'page', 'next','count'] //自定义分页布局
	                    //,curr: 5 //设定初始在第 5 页
	                    ,groups:5 //只显示 1 个连续页码
	                    ,first: false //不显示首页
	                    ,last: false //不显示尾页
	                },
	                where:{
	                	type:'3DTILES',
	                },
	                cols: [[
	                    {field: 'name', sort: false, title: '名称', align: 'left'},
	                ]],
	                done:function () {
	            	    $(".layui-table-box").css("border-width","0px");
	            	    $(".layui-table-header tr").css("height","30px");
	            	    $(".layui-table-header tr").css("background-color","#444");
	            	    $(".layui-table-header tr span").css("color","hsla(0, 0%, 100%, .8)");
	            	    $(".layui-table-body tr").css("height","30px");
	            	}
	            }); 
	            
	            form.on('submit(formSubSearchGLTF)', function (data) {
	            	bizModelForGLTFTb.reload({where: data.field}, 'data');
                });
	            form.on('submit(formSubSearch3DTILES)', function (data) {
	            	bizModel3dtilesForTb.reload({where: data.field}, 'data');
                });	  
	            
	            //监听行单击事件（双击事件为：rowDouble）
	            table.on('row(tableBizModelForGLTFEditor)', function(obj){
	            	var data = obj.data;
	            	obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
	            	_this.addGltfModelToScene(node,obj.data);
	            	layer.close(dIndex);
	            });
	            
	            //监听行单击事件（双击事件为：rowDouble）
	            table.on('row(tableBizModelFor3DTILESEditor)', function(obj){
	            	var data = obj.data;
	            	obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
	            	_this.addModelToScene(node,obj.data);
	            });
			},
			end:function(){
			}
	    });  
	});
}

SceneEditor.prototype.addModelToScene = function (node,model) {
	var _this=this;
	layer.load(2);
	var id=VFG.Util.getUuid();
	_this.globe.addModel({
		id:id,
		uri:model.url,
		name:model.name,
		type:model.type,
		callBack:function(e){
			layer.closeAll('loading');
			if(e.state==true){
		        var formData={}; 
		        formData['bizSceneModel.id']=id;
		        formData['bizSceneModel.sceneId']=_this.sceneId;
		        formData['bizSceneModel.modelId']=model.id;
		        formData['bizSceneModel.layerId']=node.id;
		        formData['bizSceneModel.name']=model.name;
		        formData['bizSceneModel.type']=model.type;
		        formData['bizSceneModel.posX']=e.param.x;
		        formData['bizSceneModel.posY']=e.param.y;
		        formData['bizSceneModel.posZ']=e.param.z;
		        formData['bizSceneModel.pitch']=e.param.rotation_x;
		        formData['bizSceneModel.roll']=e.param.rotation_z;
		        formData['bizSceneModel.heading']=e.param.rotation_y;
		        _this.ajaxFunc(_this.ctx+"/scene/model/save",formData, "json", function(res){
		            if (undefined!=res && 200==res.code) {
		        		layer.alert('成功！！', {icon: 1,skin: 'layer-ext-moon' })
		        		_this.reAsyncLayerByPId(res.data.layerId);
		            }else{
		        		layer.alert('失败！！', {icon: 3,skin: 'layer-ext-moon' })
		            }
		        });
			}else{
				layer.alert(e.message, {icon: 3,skin: 'layer-ext-moon' })
			}
		}
	})
}

SceneEditor.prototype.addGltfModelToScene = function (node,model) {
	var _this=this;
	if(this.isDraw){
		console.log('已经处于绘制状态！！！');
		return;
	}
	var primitive=null;
	_this.isDraw=true;
	var position;
	_this.drawModel=new Cesium.DrawModel(_this.viewer,{
		leftClick:function(e){
			var position=VFG.Util.getC3ToLnLa(_this.viewer,e);
			if(position){
				var id=VFG.Util.getUuid();
				primitive=_this.globe.addModel({
					id:id,
					uri:model.url,
					name:model.name,
					posX:position.x,
					posY:position.y,
					posZ:position.z,
					type:model.type
				});
				
		        var formData={}; 
		        formData['bizSceneModel.id']=id;
		        formData['bizSceneModel.sceneId']=_this.sceneId;
		        formData['bizSceneModel.modelId']=model.id;
		        formData['bizSceneModel.layerId']=node.id;
		        formData['bizSceneModel.name']=model.name;
		        formData['bizSceneModel.type']=model.type;
		        formData['bizSceneModel.posX']=position.x;
		        formData['bizSceneModel.posY']=position.y;
		        formData['bizSceneModel.posZ']=position.z;
		        _this.ajaxFunc(_this.ctx+"/scene/model/save",formData, "json", function(res){
		            if (undefined!=res && 200==res.code) {
		        		layer.msg('成功！！')
		        		_this.reAsyncLayerByPId(res.data.layerId);
		            }else{
		        		layer.msg('失败！！')
		        		_this.globe.removeModelById(id);
		            }
		        });
			}
		},
		end:function(){
			_this.isDraw=false;
			_this.drawModel=null;
			_this.addOnLineModel(node);
		}
	});
}


SceneEditor.prototype.editModel = function(node) {
	var _this=this;
	 layer.load(2);
	 _this._Ajax('get',_this.ctx+"/scene/model/setting",{modelId:node.id},'html',function(e){
		layer.closeAll();
		layer.open({
		   id:'editModel',
           type: 1,
           anim:5,
           title:'模型设置',
           area: '300px',
           content:e,
           shade:0,
           offset: ['0px', '224px'],	
           fixed:true,
           move:false,
		   skin:'layui-layer  layui-layer-adminRight layui-layer-city',
           success: function (layero, dIndex) {
              $(layero).children('.layui-layer-content').css('overflow', 'hidden');
		    	var type=$("#modelBizSceneModelType").val();
		    	if('3DTILES'==type){
		    		_this.editModel3DTILES(node.id);
		    	}
		    	else if('GLTF'==type){
		    		_this.editModelGLTF(node.id);
		    	}
			},
			end:function(){
			}
		});	
	});
}

SceneEditor.prototype.editModel3DTILES=function(id){
	var _this=this;
	  $('#translationForModelPosZ').on('input', function() {
		 var ops=form.val('modelBizSceneModelForm');  // 回显数据
    	 var primitive=VFG.Model.getById(id)
    	 if(primitive){
    		 var modelMatrix=VFG.Util.getPrimitiveModelMatrix(ops);
    		 primitive._root.transform=modelMatrix;
    	 }   
	  });
	
	  slider.render({
	     elem: '#rotateForModelRoll-slide'
	    ,max:360
	    ,min:0
	    ,step:0.1
	    ,input: true //输入框
	    ,value:$("#rotateForModelRoll-input").val()*1 || 0
	    ,change: function(value){
	    	 $("#rotateForModelRoll-input").val(value);
	         var ops=form.val('modelBizSceneModelForm');  // 回显数据
	    	 var primitive=VFG.Model.getById(id)
	    	 if(primitive){
	    		 var modelMatrix=VFG.Util.getPrimitiveModelMatrix(ops);
	    		 primitive._root.transform=modelMatrix;
	    	 } 
	       
	    }
	  });
	  
	  slider.render({
	     elem: '#rotateForModelHeading-slide'
	    ,max:360
	    ,min:0
	    ,step:0.1
	    ,input: true //输入框
	    ,value:$("#rotateForModelHeading-input").val()*1 || 0
	    ,change: function(value){
	         $("#rotateForModelHeading-input").val(value);
	         var ops=form.val('modelBizSceneModelForm');  // 回显数据
  	    	 var primitive=VFG.Model.getById(id)
  	    	 if(primitive){
  	    		 var modelMatrix=VFG.Util.getPrimitiveModelMatrix(ops);
  	    		 primitive._root.transform=modelMatrix;
  	    	 } 
	    }
	  });            	  
	  slider.render({
	     elem: '#rotateForModelPitch-slide'
	    ,max:360
	    ,min:0
	    ,step:0.1
	    ,input: true //输入框
	    ,value:$("#rotateForModelPitch-input").val()*1 || 0
	    ,change: function(value){
	        $("#rotateForModelPitch-input").val(value);
	        var ops=form.val('modelBizSceneModelForm');  // 回显数据
  	    	 var primitive=VFG.Model.getById(id)
  	    	 if(primitive){
  	    		 var modelMatrix=VFG.Util.getPrimitiveModelMatrix(ops);
  	    		 primitive._root.transform=modelMatrix;
  	    	 } 
	    }
	  });
	  
	form.on('submit(modelBizSceneModelSubmit)', function (data) {
	    layer.load(2);
	    var formData={}; 
	    for(var key in data.field){
			formData['bizSceneModel.'+key]=data.field[key];
	    }
	    _this.ajaxFunc(_this.ctx+"/scene/model/save",formData, "json", function(res){
	        layer.closeAll('loading');
	        if (res!=undefined && 200==res.code) {
	        	var data=res.data;
	            layer.msg(res.message, {icon: 1});
	            _this.reAsyncLayerByPId(data.layerId);
	        } else {
	        	 layer.msg(res.message, {icon: 1});
	        }
	    });
	
	    return false;
	});
	form.render();
}

SceneEditor.prototype.editModelGLTF=function(id){
	var _this=this;
	 $('#translationForModelPosZ').on('input', function() {
		 var value=$("#translationForModelPosZ").val();
		 _this.globe.changeModelHeight(id,value)   	
	 });
	
	 slider.render({
	     elem: '#rotateForModelRoll-slide'
	    ,max:360
	    ,min:0
	    ,step:0.1
	    ,input: true //输入框
	    ,value:$("#rotateForModelRoll-input").val()*1 || 0
	    ,change: function(value){
	    	$("#rotateForModelRoll-input").val(value);
	    	_this.globe.changeModelRoll(id,value)   	 
	    }
	  });
	  slider.render({
		     elem: '#rotateForModelHeading-slide'
		    ,max:360
		    ,min:0
		    ,step:0.1
		    ,input: true //输入框
		    ,value:$("#rotateForModelHeading-input").val()*1 || 0
	    ,change: function(value){
	        $("#rotateForModelHeading-input").val(value);
	        _this.globe.changeModelHeading(id,value)
	    }
	  });            	  
	  slider.render({
		     elem: '#rotateForModelPitch-slide'
		    ,max:360
		    ,min:0
		    ,step:0.1
		    ,input: true //输入框
		    ,value:$("#rotateForModelPitch-input").val()*1 || 0
	    ,change: function(value){
	        $("#rotateForModelPitch-input").val(value);
	        _this.globe.changeModelPitch(id,value)   	                
	    }
	  });

	  $('#scaleForModel-input').on('input', function() {
		  var value=$(this).val()*1;
		  _this.globe.changeModelScale(id,value)   
	 });
  
  	 colorpicker.render({//颜色
		elem: '#color',
		color: $("#color-input").val() || null,
		format: 'rgb',
		predefine: true,
		alpha: true,
		done: function(color) {
			$('#color-input').val(color); //向隐藏域赋值
			color || this.change(color); //清空时执行 change
			_this.globe.changeModelColor(id,color)   
			
		},
		change: function(color) {}
	 });
  	 
  	 colorpicker.render({//颜色
		elem: '#silhouetteColor',
		color:$("#silhouetteColor-input").val() || null,
		format: 'rgb',
		predefine: true,
		alpha: true,
		done: function(color) {
			$('#silhouetteColor-input').val(color); //向隐藏域赋值
			color || this.change(color); //清空时执行 change
			_this.globe.changeModelSilhouetteColor(id,color)   
		},
		change: function(color) {}
	 }); 
  	 
	  $('#silhouetteSize').on('input', function() {
		  var value=$(this).val()*1;
		  _this.globe.changeModelSilhouetteSize(id,value)   
	 });
	  
	 form.on('select(colorBlendMode)', function(data) {
		_this.globe.changeModelColorBlendMode(id,data.value)  
	 });
	 
	 form.on('select(oftenShow)', function(data) {
		_this.globe.changeModelHighlight(id,data.value)  
	 });
  
     form.on('submit(modelbizSceneModelSubmit)', function (data) {
    	layer.load(2);
	    var formData={}; 
	    for(var key in data.field){
			formData['bizSceneModel.'+key]=data.field[key];
	    }
	    _this.ajaxFunc(_this.ctx+"/scene/model/save",formData, "json", function(res){
	        layer.closeAll('loading');
	        if (res!=undefined && 200==res.code) {
	        	var data=res.data;
	            layer.msg(res.message, {icon: 1});
	            _this.reAsyncLayerByPId(data.layerId);
	        } else {
	        	 layer.msg(res.message, {icon: 1});
	        }
	    });
	    return false;
	});
	form.render();
}

